using System.Text.Json;
using System.Text.Json.Serialization;

namespace MultiAgentsClient.Service.WorkflowEngine.BuiltInNodes;

public class ListVariable<TElement>
{
    public string variableName;
    public List<TElement> listOfStr;
}

public class ListVariableConverter<TElement> : JsonConverter<ListVariable<TElement>>
{
    public override ListVariable<TElement> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
    {
        if (reader.TokenType != JsonTokenType.String)
        {
            throw new JsonException($"Expected string but got {reader.TokenType}.");
        }

        var variableName = reader.GetString();
        return new ListVariable<TElement> { variableName = variableName };
    }

    public override void Write(Utf8JsonWriter writer, ListVariable<TElement> value, JsonSerializerOptions options)
    {
        writer.WriteStringValue(value.variableName);
    }
}
